package com.zhiyou.app.config.typehandler;

import com.zhiyou.app.pojo.enums.WithdrawalStatusEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.stereotype.Component;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 提现类型处理器
 *
 * @author jonathan.z
 */
@MappedTypes(WithdrawalStatusEnum.class)
@Component
public class WithdrawalStatusHandler extends BaseTypeHandler<WithdrawalStatusEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, WithdrawalStatusEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getCode());
    }

    @Override
    public WithdrawalStatusEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String code = rs.getString(columnName);
        return WithdrawalStatusEnum.parse(code);
    }

    @Override
    public WithdrawalStatusEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String code = rs.getString(columnIndex);
        return WithdrawalStatusEnum.parse(code);
    }

    @Override
    public WithdrawalStatusEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String code = cs.getString(columnIndex);
        return WithdrawalStatusEnum.parse(code);
    }
}
